# -*- coding: utf-8 -*-
# @Author: shj
# @Date: 2020-03-30 13:30:32
# @LastEditTime: 2020-03-30 14:02:17
# @LastEditors: shj
# @Description: 找出10000以内的完美数
# @FilePath: /python3/algorithms/zhenyinzi.py
#
'''
完美数是除自身外其他所有因子的和正好等于这个数本身的数
例如: 6 = 1 + 2 + 3, 28 = 1 + 2 + 4 + 7 + 14
'''
from math import sqrt


def perfect(num_in=10000):
    for num in range(1, num_in + 1):
        sum = 0
        for no_ in range(1, int(sqrt(num)) + 1):
            if num % no_ == 0:
                sum += no_
                if no_ > 1 and num // no_ != no_:
                    sum += num // no_
        if sum == num:
            print(num)


if __name__ == "__main__":
    print("10000以内的完美数为：")
    perfect()
